let app = getApp()
var util = require('../../utils/util.js');

Page({
  data: {
    name: ['全心体验', '搜索', '圈子', '行程单', '我的'],
    currentTab: 0,
    items: [
      {
        "selectedIconPath": "/assets/image/tabs/home_h.png",
        "iconPath": "/assets/image/tabs/home.png",
        "text": "首页"
      },
      {
        "selectedIconPath": "/assets/image/tabs/search_h.png",
        "iconPath": "/assets/image/tabs/search.png",
        "text": "搜索"
      },
      {
        "selectedIconPath": "/assets/image/tabs/23.png",
        "iconPath": "/assets/image/tabs/circle_h.png",
        "text": "圈子"
      },
      {
        "selectedIconPath": "/assets/image/tabs/trip_h.png",
        "iconPath": "/assets/image/tabs/trip.png",
        "text": "行程单"
      },
      {
        "selectedIconPath": "/assets/image/tabs/me_h.png",
        "iconPath": "/assets/image/tabs/me.png",
        "text": "我的"
      }
    ]
  },
  swichNav: function (e) {
    // 进行自定义
    let that = this;
    let name = that.data.name[e.target.dataset.current];
    wx.setNavigationBarTitle({
      title: name
    })
    console.log(e.target.dataset.current)
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    }  else {
      // if (e.target.dataset.current === 4 && util.isLogin() === '') {
      //   console.log(1)
      //   wx.navigateTo({
      //     url: '/pages/login/index'
      //   })
      //   return false;
      // }
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  getUserInfo(e) {
    this.selectComponent("#me").getUserInfo(e);
  },
  onLoad: function (option) {
    if (option.id) {
      this.setData({
        currentTab: option.id
      })
    }
  },
  onSwIndex(e) {
    this.setData({
      currentTab: 4
    })
  }
})
